<template>
    <div style="text-align: left">
        <p>邮箱： lian.zuotai@inspur.com</p>
        <p>源码：https://gitee.com/lianzt/inspur-assistant</p>
        <p>使用帮助见源码页面，意见反馈可在源码页面增加评论或发送邮件。</p>
        <p>版本：{{ version }}</p>
        <p>最新：<i class="el-icon-loading" v-show="loading"></i> {{ lastVersion }}</p>
        <p v-if="message">更新：{{ message }}</p>
    </div>
</template>
<script type="text/javascript">
    import axios from 'axios'
    import { mapGetters } from 'vuex'

    export default {
        data () {
            return {
                version: 'V1.1',
                lastVersion: '',
                loading: false,
                message: ''
            }
        },
        computed: {
          ... mapGetters(['urlVersion'])
        },
        mounted () {
            this.loading = true
            axios({
                method: 'get',
                url: this.urlVersion,
                headers: {
                    'Referrer-Policy': 'unsafe-url'
                }
            }).then(response => {
                this.lastVersion = response.data.version
                if (this.lastVersion && this.lastVersion !== this.version) {
                    this.message = response.data.message
                    chrome.extension.sendMessage({ type: 'notice', notice: {
                        message: '检测到新版本：' + this.lastVersion
                    } })
                }
                this.loading = false
            }).catch(error => {
                console.log('获取版本信息失败:', error)
                this.lastVersion = '检查失败'
                this.loading = false
            })
        }
    }
</script>